# -*- coding: UTF-8 -*-
from api import client
from common.route import *
import os
import configparser
# from common.read_config import conf

data = get_yaml_filepath(Environ='data.yaml')  # 读取config下的data数据


class Update_userinfo(client.HttpClient):

    def __init__(self, token):
        super().__init__()
        self.host = data['admin_host']
        config_path = os.path.abspath(
            os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + r'\configs\token.ini')
        conf = configparser.ConfigParser()
        conf.read(config_path, encoding='utf-8-sig')
        test_token = conf.get('token', '{}'.format(token))
        self.token = test_token

    """修改个人信息接口封装"""

    def update_userinfo(self,trueName, birthYear, birthMonth, birthDay, gender):
        """

        :param trueName: 用户民
        :param birthYear: 生日年份
        :param birthMonth: 生日月份
        :param birthDay: 生日日期
        :param gender: 性别
        :return:
        """
        url = update_userinfo['url']
        url = self.get_full_url(url)
        body = {"trueName": trueName, "birthYear": birthYear, "birthMonth": birthMonth, "birthDay": birthDay,
                "gender": gender}
        method = update_userinfo['method']
        return self.send(url, method=method, body=body, token=self.token)

    """api新增地址"""

    def add_address(self, address_name, phone, address, houseNumber, latitude, longitude, isDefault, tagCode):
        """

        :param address_name: 地址名称
        :param phone: 联系电话
        :param address: 地址
        :param houseNumber: 门牌号
        :param latitude: 纬度
        :param longitude: 经度
        :param isDefault: 是否默认
        :param tagCode: 地址类型 1.家 2.父母家 3.公司
        :return:
        """
        url = add_address['url']
        url = self.get_full_url(url)
        method = add_address['method']
        body = {"name": address_name, "phone": phone, "address": address, "houseNumber": houseNumber,
                "latitude": latitude, "longitude": longitude, "isDefault": isDefault, "tagCode": tagCode}
        return self.send(url, method=method, body=body, token=self.token)

    """api显示所有地址"""

    def address_list(self):
        url = address_list['url']
        url = self.get_full_url(url)
        method = address_list['method']
        return self.send(url, method=method, token=self.token)

    """api删除地址"""

    def delete_address(self, address_id):
        """

        :param address_id: 地址id
        :return:
        """
        url = "/customer/address/delete/{}".format(address_id)
        url = self.get_full_url(url)
        method = 'post'
        body = {}
        return self.send(url, method=method, body=body, token=self.token)
